var fetch = require('node-fetch')
var express = require('express');
var router = express.Router();
var client = require('./config')

router.post('/huanyuan',function (req,res) {
    res.json(req.body);
})


//参数 imgbase
router.post('/',function(req,res){
    var body = {
        "image":  req.body.imgbase,
        "configure":{
            "min_size" : 4,
            "output_prob" : true
        }
    };
    console.log("传过来的json",body)
    fetch('http://tysbgpu.market.alicloudapi.com/api/predict/ocr_general', {
        method: 'POST',
        body:    JSON.stringify(body),
        headers: { 'Content-Type': 'application/octet-stream; charset=utf-8',
            'Authorization':'APPCODE faae2d7ba46e4fbab71bb0e757fbd69e'
        },
    })
        .then(resa => resa.json())
        .then(json => res.send(json));
})

//参数 imgbase ,高精度搜索
router.post('/nb',function(req,res){
    // 调用通用文字识别（高精度版）
    client.accurateBasic(req.body.imgbase).then(function(result) {
        console.log(JSON.stringify(result));
        res.send(JSON.stringify(result))
    }).catch(function(err) {
        // 如果发生网络错误
        console.log(err);
    });
})
router.post('/zsyzm',function(req,res){

    var body = {
        "region": "cn",
        "phone": "86"+req.body.phone
    };
    // console.log("传过来的json",body)
    fetch('http://service.h7tuho5mf.cn/api/v1/verification_code?lc=0000000000000077&cc=TG0001&cv=Trivia1.2.0_iphone&proto=13&idfa=00000000-0000-0000-0000-000000000000&idfv=B03CE1D8-0DED-4C8D-A8D9-7FAC49EB9616&devi=e698a33ac80a06cfc54ea7182b4ff5f6e8a4a8e3&osversion=ios_10.200000&ua=iPhone8_1&imei=&imsi=&uid=&sid=&conn=wifi&mtid=eceaedb05d69bac35fd0c0ad90081104&mtxid=ac393a9aadeb&logid=&smid=D2a1Jy/xU54PNc0qin0Ivvz20T4nG7R8J4UG7BadHTvZ4Xa8', {
        method: 'POST',
        body:    JSON.stringify(body)
    })
        .then(resa => resa.json())
        .then(json => res.send(json));
})
    // var a = 0
router.post('/zslogin',function(req,res){
    // a++
    // if (a>=10){
    //     res.send("超过10次")
    //  return;
    // }
    var body = {
        "region": "cn",
        "phone": "86"+req.body.phone
    };
    // console.log("传过来的json",body)
    fetch('http://service.h7tuho5mf.cn/api/v1/login?lc=0000000000000077&cc=TG0001&cv=Trivia1.2.0_iphone&proto=13&idfa=00000000-0000-0000-0000-000000000000&idfv=B03CE1D8-0DED-4C8D-A8D9-7FAC49EB9616&devi=e698a33ac80a06cfc54ea7182b4ff5f6e8a4a8e3&osversion=ios_10.200000&ua=iPhone8_1&imei=&imsi=&uid=&sid=&conn=wifi&mtid=eceaedb05d69bac35fd0c0ad90081104&mtxid=ac393a9aadeb&logid=&smid=D2a1Jy/xU54PNc0qin0Ivvz20T4nG7R8J4UG7BadHTvZ4Xa8', {
        method: 'POST',
        body:    JSON.stringify(body)
    })
        .then(resa => resa.json())
        .then(json => res.send(json));
})
//dengru
router.post('/login',function(req,res){

    var body = {
        "code": req.body.code,
        "phone": "86"+req.body.phone,
        "request_id": req.body.request_id,
        "platform": "phone"
    };

    console.log("传过来的json",body)
    fetch('http://service.h7tuho5mf.cn/api/v1/login?lc=0000000000000077&cc=TG0001&cv=Trivia1.2.0_iphone&proto=13&idfa=00000000-0000-0000-0000-000000000000&idfv=B03CE1D8-0DED-4C8D-A8D9-7FAC49EB9616&devi=e698a33ac80a06cfc54ea7182b4ff5f6e8a4a8e3&osversion=ios_10.200000&ua=iPhone8_1&imei=&imsi=&uid=&sid=&conn=wifi&mtid=eceaedb05d69bac35fd0c0ad90081104&mtxid=ac393a9aadeb&logid=&smid=D2a1Jy/xU54PNc0qin0Ivvz20T4nG7R8J4UG7BadHTvZ4Xa8', {
        method: 'POST',
        body:    JSON.stringify(body)
    })
        .then(resa => resa.json())
        .then(json => res.send(json));
})

//刷复活卡
//刷复活卡
router.post('/fuhuo',function(req,res){

    var urlstr = "http://service.h7tuho5mf.cn/api/invite_code/bind?code="+req.body.inviteCode+"&lc=0000000000000077&cc=TG0001&cv=Trivia1.2.0_iphone&proto=13&idfa=00000000-0000-0000-0000-000000000000&idfv=B03CE1D8-0DED-4C8D-A8D9-7FAC49EB9616&devi=e698a33ac80a06cfc54ea7182b4ff5f6e8a4a8e3&osversion=ios_10.200000&ua=iPhone8_1&imei=&imsi=&uid="+req.body.uid+"&sid="+req.body.session+"&conn=wifi&mtid=eceaedb05d69bac35fd0c0ad90081104&mtxid=ac393a9aadeb&logid=&smid=D2a1Jy/xU54PNc0qin0Ivvz20T4nG7R8J4UG7BadHTvZ4Xa8"

    console.log("传过来的url",urlstr)
    fetch(urlstr, {
        method: 'GET'
        // body:    JSON.stringify(body)
    })
        .then(resa => resa.json())
        .then(json => res.send(json));
})
//西瓜验证码
router.post('/xgyzm',function (req,res) {
    var dic = {
        '1':'34',
        '2':'37',
        '3':'36',
        '4':'31',
        '5':'30',
        '6':'33',
        '7':'32',
        '8':'3d',
        '9':'3c',
        '0':'35'
    }
    var mobile = req.body.phone
    var newmobile = ''
    for(var i=0;i<mobile.length;i++)
    {
        newmobile = newmobile+dic[mobile.charAt(i)]
    }

    var body= 'mobile='+newmobile+'&type=3730&unbind_exist=0'
    console.log("body=",body)
    var urlstr = "https://security.snssdk.com/passport/mobile/send_code/?mix_mode=1&version_code=6.2.9&app_name=video_article&vid=1BF50C07-468D-474F-AB35-F4AC59DF8E66&device_id=46409721287&channel=App%20Store&resolution=750*1334&aid=32&ab_version=256481,253648,221020,246275,249883,256322,248263,249818,217525,252881,240348,255490,235684,249824,249820,249827,249830,251024,150151&openudid=5469c5acf005d8b0556698bf34e3b3a80e53ea14&live_sdk_version=1.3.0&idfv=1BF50C07-468D-474F-AB35-F4AC59DF8E66&ac=WIFI&os_version=11.2&user_version=2.2.9&ssmix=a&device_platform=iphone&iid=23498558751&ab_client=a1,f2,f7,e1&device_type=iPhone%206S&idfa=00000000-0000-0000-0000-000000000000"
    console.log("传过来的json",body)
    fetch(urlstr, {
        method: 'POST',
        body:    body,
        credentials: 'include',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
        .then(resa => resa.json())
        .then(json => res.send(json));

})
//西瓜视频登入
router.post('/xgyzmlogin',function (req,res) {
    var dic = {
            '1':'34',
            '2':'37',
            '3':'36',
            '4':'31',
            '5':'30',
            '6':'33',
            '7':'32',
            '8':'3d',
            '9':'3c',
            '0':'35'
        }
    var mobile = req.body.phone
    var code =  req.body.code
    var newmobile = ''
    var newcode = ''
    for(var i=0;i<mobile.length;i++)
    {
        newmobile = newmobile+dic[mobile.charAt(i)]

    }
    for (var i = 0; i < code.length; i++) {
        newcode = newcode+dic[code.charAt(i)]
    }

    var body= 'code='+newcode+'&mobile='+newmobile
    console.log("看看登入传来的body",body)
    var urlstr = "https://security.snssdk.com/passport/mobile/sms_login/?mix_mode=1&version_code=6.2.9&app_name=video_article&vid=1BF50C07-468D-474F-AB35-F4AC59DF8E66&device_id=46409721287&channel=App%20Store&resolution=750*1334&aid=32&ab_version=256481,253648,221020,246275,249883,256322,248263,249818,217525,252881,240348,255490,235684,249824,249820,249827,249830,251024,150151&openudid=5469c5acf005d8b0556698bf34e3b3a80e53ea14&live_sdk_version=1.3.0&idfv=1BF50C07-468D-474F-AB35-F4AC59DF8E66&ac=WIFI&os_version=11.2&user_version=2.2.9&ssmix=a&device_platform=iphone&iid=23498558751&ab_client=a1,f2,f7,e1&device_type=iPhone%206S&idfa=00000000-0000-0000-0000-000000000000"
    fetch(urlstr, {
        method: 'POST',
        body:    body,
        credentials: 'include',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
        .then(resa => resa.json())
        .then(json => res.send(json));

})
//西瓜刷复活
router.post('/xgfuhuo',function (req,res) {
     var sessionkey = req.body.sessionkey
     var uid=req.body.uid
     var invitecode=req.body.invitecode
     console.log("dsd",req.body)
    fetch("https://api-spe-c.snssdk.com/h/1/cli/check_invite/?version_code=6.2.9&app_name=video_article&vid=1BF50C07-468D-474F-AB35-F4AC59DF8E66&device_id=46409721287&channel=App%20Store&resolution=750*1334&aid=32&ab_version=256481,253648,221020,246275,249883,256322,248263,249818,217525,252881,240348,255490,235684,249824,249820,249827,249830,251024,150151&openudid=5469c5acf005d8b0556698bf34e3b3a80e53ea14&live_sdk_version=1.3.0&idfv=1BF50C07-468D-474F-AB35-F4AC59DF8E66&ac=WIFI&os_version=11.2&user_version=2.2.9&ssmix=a&device_platform=iphone&iid=23498558751&ab_client=a1,f2,f7,e1&device_type=iPhone%206S&idfa=00000000-0000-0000-0000-000000000000", {
        method: 'POST',
        body: invitecode,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        credentials: 'include'
    }).then(resa=>res.json(resa))
})
module.exports = router;
